//数据库-用户注册VIP
const cloud = require('wx-server-sdk')
const db = cloud.database()
const _ = db.command

exports.main = async (event, context) => {
  var no = Math.floor(Math.random() * 999999);
  var date = new Date();
  var key = date.getTime() + "" + no;//暂时这样写。
  try {
    return await db.collection('userInfo').where({
      openid: event.openid
    })
    .update({
      data: {
        viplevel: _.set(1),
        regInfo: _.set(event.regInfo)
      },
    })
  } catch(e) {
    console.error("database setUserRegister error!-->")
    console.error(e)
  }
}